<%@page import="java.io.* , java.util.*, java.sql.*, com.myapp.struts.actionform.*, com.myapp.struts.dao.*, com.myapp.struts.beans.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
        <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
        <title>Edit Location</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../../../../css/cms.css" rel="stylesheet" type="text/css">
        <script language="javascript">
        function Validate()
        {
         var index3=document.editloc.locationCode.selectedIndex;                        
                        if(index3<=0)
                        {
                            alert("Please Enter a Location Code....");                            
                            document.editloc.locationCode.focus();
                            return false;
                        }

                        if(document.getElementById("locationName").value == "")
                        {                            
                            alert("Please Enter Location Name....");
                            document.getElementById("locationName").focus();                            
                            return false;
                        }
                        }
		</script>
        <script type="text/javascript">

            function getXMLObject()  //XML OBJECT
            {
                var xmlHttp = false;
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
                }
                catch (e) {
                    try {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
                    }
                    catch (e2) {
                        xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
                    }
                }
                if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
                    xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
                }
                return xmlHttp;  // Mandatory Statement returning the ajax object created
            }

            var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

            function getLocationDetails() {
                var sel = document.getElementById("locationCode");
                var opt = sel.options[sel.selectedIndex];
                var d = opt.value || opt.text;

                if(xmlhttp) {
                    xmlhttp.open("POST","../../../../AJAXLocations?locname=" +d,true);
                    xmlhttp.onreadystatechange  = handleServerResponse;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send(null);
                }
            }

            function handleServerResponse() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById('locationName').value= 0;
			                       
                        var textToSplit = xmlhttp.responseText;
                        var returnElements=textToSplit.split("|");
                        valueLabelPair = returnElements[1].split("|");
                        document.getElementById('locationName').value=valueLabelPair;
                    }else {
                        alert("Error during AJAX call. Please try again");
                    }
                }
            }
            
        </script>
    </head>
    <body >
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td height="547" valign="top" >
                    <form action="../../../../EditLocation" method="post" enctype="application/x-www-form-urlencoded" name="editloc" id="editloc" onSubmit="return Validate();">
                        <table width="288" border="0" align="center" cellpadding="0" cellspacing="0" style="border-right: #000000 1px solid;
                               border-top: #000000 1px solid; border-left: #000000 1px solid;  border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                            <tr>
                                <th height="28" colspan="2" align="center" valign="middle"><strong>EDIT SITE</strong> </th>
                            </tr>
                            <tr>
                                <td width="142"><span class="style1"> SITE CODE</span></td>
                                <td width="144"><span id="spryselect1">
                                        <select name="locationCode" id="locationCode" onChange="javascript:getLocationDetails()">
                                            <option> </option>
                                            <%
                              LocationMasterDao imdao = new LocationMasterDao();
                              Vector gp = imdao.getLocations();
                              if (gp != null) {
                                  Iterator itg = gp.iterator();
                                  while (itg.hasNext()) {
                                      LocationMasterFormBean gb = (LocationMasterFormBean) itg.next();
                                      String pname = gb.getLocationCode();
                                            %>
                                            <option value="<%=pname%>"><%=pname%></option>
                                            <%}

                              }%>
                                        </select>
                                    </span></td>
                            </tr>
                            <tr >
                                <td valign="middle"><span class="style1">SITE NAME</span></td>
                                <td valign="middle"><label><span id="sprytextfield1">
                                            <input type="text" name="locationName" id="locationName" />
                                        </span></label></td>
                            </tr>
                            <tr >
                                <td colspan="2" align="center" valign="middle"><input name="Submit" type="submit" class="subHeader" value="Edit" /></td>
                            </tr>
                        </table>
                    </form></td>
            </tr>

            <tr>
                <td background="images/flash_body1.png">&nbsp;</td>
            </tr>
        </table>
    </body>
</html>
